<template>
  <div>
    <div class="list-navbar">
      <van-nav-bar :title="title" left-text="返回" left-arrow @click-left="handleReturn" />
      <van-dropdown-menu>
        <van-dropdown-item v-model="sortValue" :options="sortOption" @change="handleSortChange" />
        <van-dropdown-item
          v-model="updateValue"
          :options="updateOption"
          @change="handleUpdateChange"
        />
        <van-dropdown-item v-model="overValue" :options="overOption" @change="handleOverChange" />
      </van-dropdown-menu>
    </div>
    <div class="list-cotent">
      <van-list
        v-model="loading"
        :finished="finished"
        finished-text="没有更多了"
        @load="onLoad"
        v-if="list.length > 0"
      >
        <detailCard
          v-for="(item, index) in list"
          :name="item.name"
          :writer="item.writer"
          :is_over="item.is_over"
          :type="item.type"
          :intro="item.intro"
          :id="item.id"
          :image="item.image"
          :key="index"
        ></detailCard>
      </van-list>

      <van-empty v-else description="没有更多了" />
    </div>
  </div>
</template>
<script>
import Taro, { getCurrentInstance } from "@tarojs/taro";
import { getSearchList } from "@api/list";
import DetailCard from "@components/DetailCard";
export default {
  name: "booklist",
  components: { DetailCard },
  data() {
    return {
      title: "分类列表",
      type: 0,
      sortValue: 0,
      sortOption: [
        { text: "正序", value: 0 },
        { text: "倒序", value: 1 }
      ],
      updateValue: 0,
      updateOption: [
        { text: "全部", value: 0 },
        { text: "三日内", value: 3 },
        { text: "一周内", value: 7 },
        { text: "半月内", value: 15 },
        { text: "一月内", value: 30 }
      ],
      overValue: 0,
      overOption: [
        { text: "全部", value: 0 },
        { text: "连载中", value: 1 },
        { text: "已完本", value: 2 }
      ],
      finished: true,
      loading: false,
      list: []
    };
  },
  created() {
    const { title, type } = getCurrentInstance().router.params;
    this.title = decodeURI(title);
    this.type = type;
    this.getList(type);
  },
  methods: {
    getList(type) {
      let params = {
        type,
        updateDay: this.updateValue,
        isOver: this.overValue
      };
      getSearchList(params).then(res => {
        this.list = res.data.data;
      });
    },
    handleReturn() {
      Taro.navigateBack();
    },
    handleSortChange(e) {
      this.list.reverse();
    },
    handleUpdateChange(e) {
      this.getList(this.type);
    },
    handleOverChange(e) {
      this.getList(this.type);
    },
    onLoad(e) {}
  }
};
</script>
<style scoped>
.list-navbar {
  position: fixed;
  width: 100%;
  z-index: 10;
  top: 0;
}
.list-cotent {
  padding: 40px;
  margin-top: 94Px;
  z-index: 1;
}
</style>